# Contributor: August Klein <amatcoder@gmail.com>
# Maintainer: André Klitzing <aklitzing@gmail.com>
pkgname=cppcheck
pkgver=2.8.1
pkgrel=0
pkgdesc="Static analysis tool for C/C++ code"
url="https://cppcheck.sourceforge.io/"
# riscv64 broken, "Could not find qmake spec 'default'."
arch="all !riscv64"
license="GPL-3.0-or-later"
makedepends="docbook-xsl pcre-dev python3 qt5-qttools-dev tinyxml2-dev qtchooser"
subpackages="$pkgname-doc $pkgname-htmlreport::noarch $pkgname-gui"
source="$pkgname-$pkgver.tar.gz::https://github.com/danmar/cppcheck/archive/$pkgver.tar.gz
	set_datadir.patch
	python3-htmlreport.patch
	"

build() {
	# HACK get python to mean what we want
	ln -s /usr/bin/python3 python
	export PATH="$(pwd):$PATH"

	make DB2MAN=/usr/share/xml/docbook/xsl-stylesheets-*/manpages/docbook.xsl man

	cd gui
	lrelease-qt5 gui.pro
	qmake-qt5 HAVE_RULES=yes
	make SRCDIR=build CFGDIR=/usr/share/cppcheck/cfg HAVE_RULES=yes FILESDIR=/usr/share/cppcheck
}

check() {
	make SRCDIR=build check
}

package() {
	make DESTDIR="$pkgdir" CFGDIR=/usr/share/cppcheck/cfg HAVE_RULES=yes FILESDIR=/usr/share/cppcheck install
	install -Dm644 cppcheck.1 "$pkgdir"/usr/share/man/man1/cppcheck.1
}

htmlreport() {
	pkgdesc="Utility to generate a html report of a XML file produced by cppcheck"
	depends="$pkgname python3 py3-pygments"

	cd "$builddir"
	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/$subpkgname "$subpkgdir"/usr/bin/
}

gui() {
	pkgdesc="Qt gui for cppcheck"
	depends="$pkgname"

	cd "$builddir"
	mkdir -p "$subpkgdir"/usr/bin
	mv gui/$subpkgname "$subpkgdir"/usr/bin/

	mkdir -p "$subpkgdir"/usr/share/cppcheck/lang/
	mv gui/cppcheck*.qm "$subpkgdir"/usr/share/cppcheck/lang/
}

sha512sums="
ff5a9955498101a2d061a431d0f8ed42267627b3cd029302871ee781a0e4039aa531dd47c2d44d1f3952b5e5bd3b65c9b32a10a9b1922ef466f440f8c4417e28  cppcheck-2.8.1.tar.gz
ebc9cf95f51afe52094f51fa82ae76a6f52b63c5f94df512b61c939328fc0d3e8c681644c61368f3d3267bf6c0a155604cc00b20e49fd196d788a357655a9d43  set_datadir.patch
346c5b41af809dfbff00b7ce66f8abc0e038d6272cf08bbefc4bfc6eaf32940815faca376609165de85072761271521c2a7a56aa7c59e88f65f7d9514b35aaff  python3-htmlreport.patch
"
